<template>
  <a-modal
      width='409px'
      title='交付物状态设定'
      cancelText="取消"
      okText="确定"
      :visible="visible"
      :confirmLoading='confirmLoading'
      @ok="handleOk"
      @cancel="handleCancel">
      <a-form>
        <a-form-item label="状态：">
          <a-select placeholder="请选择状态" class="width_268" v-model="selectStart">
            <a-select-option v-for="(item, index) in selectArr" :key="index" :value="item.value" > {{item.lable}}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
  </a-modal>
</template>
<script>
import { mapGetters } from 'vuex'
import { getLifeCycleTemplate, setLifeCycleState } from "@/api/fileSingle.js"
export default {
  data() {
    return {
      ischeckHref: '',
      selectStart: '',
      confirmLoading: false,
      visible: false,
      statusSettingArr: [],
      selectArr: [],
      setParmasData: []
    }
  },
  computed: {
    ...mapGetters({
      'fileSingleData': 'fileSingle'
    })
  },
  props: {
    sessionData: {
      type: Array,
      default: () => []
    },//存入的session
  },
  methods: {
    handleOk () {
      this.confirmLoading = true
      setLifeCycleState({oid: this.setParmasData[0].oid, state: this.selectStart}).then((res) => {
        if (res && res.data.success) {
          if (this.ischeckHref) {
            this.$emit('initSigoView')
          }
          this.$emit('initTableData')
          this.$message.success('修改成功')
          this.visible = false
        } else {
          this.$message.error(res.data.message)
        }
        this.confirmLoading = false
      })
    },
    handleCancel () {
      this.visible = false
    },
    initData (val) {
      getLifeCycleTemplate({oid: val[0].oid}).then((res) => {
        if (res && res.data.success) {
          let data = res.data.data[0]
          this.selectArr = data.selects
          this.selectArr.map(item => {
            if (item.lable === data.state) {
              this.selectStart = item.value
            }
          })
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    /**
     * 开启弹窗
     * key 上级需要开启那个弹窗的key props上级tree选中的tree，propsArr 上级table选中的数据
     */
    openModal (start, props, propsArr, ischeckHref) {
      // debugger
      this.visible = start
      this.setParmasData = props
      /*this.statusSettingArr = propsArr
      this.ischeckHref = ischeckHref*/
      this.initData(props)
    }
  }
}
</script>
<style lang="less" scoped>
.width_268 {
  width: 268px;
}
</style>